import request from '@/utils/request'

/**
 * 采购申请分页查询
 * @param {*} data = {pageNo: 0, pageSize: 0, param: {status,storeId}}
 */
export function pageList(form, pageSize, currentPage) {
  const data = {
    param: form,
    pageSize: pageSize,
    pageNo: currentPage
  }
  return request.post('/sq/brandPurchaseRecord/page', data)
}

/**
 * 配件分页查询
 * @param {*} data = {pageNo: 0, pageSize: 0, param: {purchaseRecordId}}
 */
export function partsPage(form, pageSize, currentPage) {
  const data = {
    param: form,
    pageSize: pageSize,
    pageNo: currentPage
  }
  return request.post('/sq/brandPurchaseRecord/partsPage', data)
}

/**
 * 新增采购申请
 * @param {*} data
 */
export function save(data) {
  return request.post('/sq/brandPurchaseRecord/save', data)
}

/**
 * 更新采购申请
 * @param {*} data
 */
export function update(data) {
  return request.put('/sq/brandPurchaseRecord/save', data)
}

/**
 * 删除采购申请
 * @param {*} id
 */
export function deleteById(id) {
  return request.delete(`/sq/brandPurchaseRecord/del/${id}`)
}

/**
 * 编辑采购申请详情
 * @param {*} id
 */
export function editDetailById(id) {
  return request.get(`/sq/brandPurchaseRecord/findById/${id}`)
}

/**
 * 采购申请详情
 * @param {*} id
 */
export function detailById(id) {
  return request.get(`/sq/brandPurchaseRecord/detail/${id}`)
}

/**
 * 获取采购单编号
 */
export function getPurchaseCode() {
  return request.get(`/sq/brandPurchaseRecord/getPurchaseCode`)
}

/**
 * 根据采购编号找配件
 * data={code, supplierId}
 */
export function findPartsByCode(data) {
  return request.post(`/sq/brandPurchaseRecord/findPartsByCode`, data)
}

/**
 * 更新采购状态
 * @param {*} data
 */
export function updateStatus(id, status) {
  return request.put(`/sq/brandPurchaseRecord/updateStatus?id=${id}&status=${status}`)
}
